package com.alili.springbooteditor.dao;

import com.alili.springbooteditor.entities.messages;
import com.alili.springbooteditor.repository.MessagesRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;

@Repository
public class MessagesDao {
    @Autowired
    MessagesRepository messagesRepository;
    public void save(messages message){
        messagesRepository.save(message);
    }
    public void deleteMessage(Integer id){
        messagesRepository.deleteById(id);
    }
    public Page<messages> findAllMessagesAndSortBymessageId(Integer pageNum){
        PageRequest pageable = PageRequest.of(pageNum, 3, Sort.Direction.DESC, "messageId");
        Page<messages> p = messagesRepository.findAll(pageable);//按照日期排序显示
        return p;
    }
}
